package com.groot.medical.service;

import com.groot.medical.dao.AdministrativeAreaDao;
import com.groot.medical.dao.AdministrativeAreaDaoImpl;
import com.groot.medical.dao.InstitutionDao;
import com.groot.medical.dao.InstitutionDaoImpl;
import com.groot.medical.entity.AdministrativeArea;
import com.groot.medical.entity.PageBean;
import com.groot.medical.entity.RuralInstitution;

public class InstitutionServiceImpl implements InstitutionService {
	private InstitutionDao institutionDao = new InstitutionDaoImpl();
	private AdministrativeAreaDao areaDao = new AdministrativeAreaDaoImpl();
	@Override
	public PageBean findByPage(int pageNum, int pageSize) {
		int totalRecord = institutionDao.getAllInstitutionCount();
		PageBean pageBean = new PageBean<>(pageNum, pageSize, totalRecord);
		int startIndex = pageBean.getStartIndex();
		pageBean.setList(institutionDao.findInstitutionCByPage(startIndex,pageSize));
		return pageBean;
	}

	@Override
	public int addInstitutionInfo(RuralInstitution institution,String pid) {
		//获取行政区域信息
		AdministrativeArea parea=areaDao.findLevelByPid(Integer.parseInt(pid));
		//
		institution.setInstitutionLevel(parea.getAreaLevel());
		institution.setAreacode(parea.getAreaCode());
		return institutionDao.addInstitutionInfo(institution);
	}

	@Override
	public RuralInstitution findInstitutionInfoById(String id) {
		RuralInstitution institution = institutionDao.findInstitutionInfoById(id);
		return institution;
	}

	@Override
	public void editInstitutionInfo(RuralInstitution institution) {
		institutionDao.editInstitutionInfo(institution);
	}

}
